package no.ntnu.fp.model;




public class Date {
	private int year;
	private int month;
	private int day;
	
	public Date() {
		year = 0;
		month = 0;
		day = 0;
	}
	
	public Date(int year, int month, int day) {
		this.year = year;
		this.month = month;
		this.day = day;
	}
	
	public Date(String date) {
		this.year = Integer.parseInt(date.substring(0,4));
		this.month = Integer.parseInt(date.substring(5,7));
		this.day = Integer.parseInt(date.substring(8,10));
	}
	
	public int getWeek() {
		int days = (month-1)*30 + day;
		int week = days/7;
		return week;
	}
	
	public int getYear() {
		return year;
	}
	
	public int getMonth() {
		return month;
	}
	
	public int getDay() {
		return day;
	}
	
	public  void setYear(int year) {
		this.year = year;
	}
	
	public void setMonth(int month) {
		this.month = month;
	}
	
	public void setDay(int day) {
		this.day = day;
	}
	
	public String toString() {
		String y, m, d;
		if (year < 10) {
			y = "000"+year;
		}
		else if (year < 100) {
			y = "00"+year;
		}
		else if (year < 1000) {
			y = "0"+year;
		}
		else {
			y = String.valueOf(year);
		}
		if (month < 10) {
			m = "0"+month;
		}
		else {
			m = String.valueOf(month);
		}
		if (day < 10) {
			d = "0"+day;
		}
		else {
			d = String.valueOf(day);
		}
		return y+"-"+m+"-"+d;
	}
	
	/**
	 * 
	 * 
	 * @param time
	 * @return 0 if equal, 1 if date > this, -1 if date < this
	 */
	public int compareTo(Date date) {
		if (this.year < date.getYear()) {
			return 1;
		}
		else if (this.year > date.getYear()) {
			return -1;
		}
		else {
			if (this.month < date.getMonth()) {
				return 1;
			}
			else if (this.month > date.getMonth()) {
				return -1;
			}
			else {
				if (this.day < date.getDay()) {
					return 1;
				}
				else if (this.day > date.getDay()) {
					return -1;
				}
			}
		}
		return 0;
	}
}